package com.t01.bdqn.common;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;


@ControllerAdvice
public class T01ExceptionHandler {

    //需要处理的异常类型 ： Exception
    @ExceptionHandler(value = Exception.class)
    @ResponseBody//返回json数据给前端
    public ApiResult handler(Exception e){
        e.printStackTrace();
        return  new ApiResult(201,e.toString());
    }

    //需要处理的异常类型为： SQLException
    @ExceptionHandler(value = SQLException.class)
    @ResponseBody//返回json数据给前端
    public Map<String,Object> handlerSQLException(Exception e){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("msg",e.toString());
        resultMap.put("statuCode",202);
        return  resultMap;
    }



}
